/**
 * 城市选择器
 * 
 * @author zhouqi 2011-12-23 PM 03:00:12
 */
(function(undefined){
	var city_obj = {};
	
	//选择器配置
	city_obj.config = {
		//效果
		effect:'',
		//城市数据
		data:'',
		//偏移量
		offset:{},
		//城市点击后触发的事件
		city_click:'',		
		//触发对象
		trigger:''
	}
	
	//主盒子
	city_obj.main_box = '',
	
	//选择器初始化
	city_obj.init = function(param) {
		if(!param || param.data == undefined || !param.trigger) {
			return;
		}
		
		//合并配置
		common_fun_obj.merge_config(city_obj.config, param);		
        
        //生成样式
        var _style = config.path.plugin + 'city/main.css?v=' + config.version
        common_fun_obj.append_style(_style);
				
		//绑定效果
		city_obj.config.trigger.bind('click', city_obj.effect[city_obj.config.effect]);
		
		$(document.body).bind('click', city_obj.unit.hide);
	}
	
	//城市部件
	city_obj.unit = {
		show:function() {
			!city_obj.main_box || city_obj.main_box.show();					
		},
		hide:function(e) {
			!city_obj.main_box || city_obj.main_box.hide();					
		}
	}
	
	//效果
	city_obj.effect = {
		//下拉效果
		droplist:function() {
			
		},
		//搜搜选择效果
		soso:function() {			
			if(city_obj.main_box) {
				city_obj.unit.show();
				return false;
			}
			
			//配置信息
			var _config = city_obj.config;
			
			//获取对象位置
			var pos = _config.trigger.offset();
			
			city_obj.main_box = $('<div></div>');
			city_obj.main_box.css({
				left: pos.left + _config.offset.l,
				top: pos.top + _config.offset.t,
                'z-index':1,
				position: 'absolute'				
			});
			
			var str = '<div class="pop_window">' +                      
                      '<div class="hotcitylist">';
            _config.data.unshift({'0':'', '1':'全国'});
			for(v in _config.data) {
				if(_config.data[v][1] == '不限') {
					continue;
				}
                if(_config.data[v][1] == '全国') {
                    str += '<span><a href="javascript:;return false;" style="color:red;">' + _config.data[v][1] + '</a></span>';                 
                    continue;
                }
				str += '<span><a href="javascript:;">' + _config.data[v][1] + '</a></span>'; 				
			}
			str += '<br></div></div>';
			city_obj.main_box.html(str);
			city_obj.main_box.find('a').bind('click', _config.city_click);								
			
			$(document.body).append(city_obj.main_box);						
			return false;
		}
	}
	
	if(window.city_obj == undefined) {
		window.city_obj = city_obj;
	}	
})();
